package com.hiray.demos.ui_architect.litho.custom

import android.graphics.Color
import com.facebook.litho.Border
import com.facebook.litho.Component
import com.facebook.litho.ComponentContext
import com.facebook.litho.Row
import com.facebook.litho.annotations.LayoutSpec
import com.facebook.litho.annotations.OnCreateLayout
import com.facebook.litho.annotations.Prop
import com.facebook.litho.widget.Text
import com.facebook.yoga.YogaEdge
import com.hiray.demos.R

@LayoutSpec(value = "LabelView")
object LabelComponentSpec {

    @OnCreateLayout
    fun onCreateLayout(c: ComponentContext, @Prop labels: List<String>): Component {
        val builder = Row.create(c)
        labels.forEachIndexed { index, it ->
            builder.child(Text.create(c)
                    .text(it)
                    .textColor(Color.parseColor("#E6817C"))
                    .paddingDip(YogaEdge.START, 4f)
                    .paddingDip(YogaEdge.END, 4f)
                    .backgroundRes(R.drawable.label_bg)//use border
                    .border(Border.create(c)
                            .color(YogaEdge.ALL, Color.parseColor("#E6817C"))
                            .radiusDip(2f)
                            .build())
                    .marginDip(YogaEdge.LEFT, if (index != 0) 9f else 0f)
                    .textSizeSp(13f)
                    .build())
        }
        return builder.build()
    }
}